package main.ServiceImpli;
//
///**
// * 作者: ALIM-MASTIK
// * 创建实现: 2023/7/15 9:31
// * 项目名称：chat
// * 软件: IntelliJ IDEA
// */

import main.Daoimpl.ChatMessageDAOImpl;
import main.JdbcUtils;
import main.Service.ChatMessageService;
import main.dao.ChatMessageDAO;
import main.pojo.ChatMessage;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class ChatMessageServiceImpl implements ChatMessageService {

    private ChatMessageDAO chatMessageDAO;

    public ChatMessageServiceImpl(Connection connection) {
        chatMessageDAO = new ChatMessageDAOImpl(connection);
    }
    public ChatMessageServiceImpl(){
        chatMessageDAO= new ChatMessageDAOImpl(JdbcUtils.getConnection());
    }

    @Override
    public ChatMessage getChatMessageByID(int messageID) {
        return chatMessageDAO.getChatMessageByID(messageID);
    }

    @Override
    public List<ChatMessage> getChatMessagesByUser(int userID) {
        return chatMessageDAO.getChatMessagesByUser(userID);
    }

    @Override
    public List<ChatMessage> getChatMessagesByChatRoom(int chatRoomID) {
        return chatMessageDAO.getChatMessagesByChatRoom(chatRoomID);
    }

    @Override
    public List<ChatMessage> getAllChatMessages() {
        try {
            return chatMessageDAO.getAllChatMessages();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Boolean createChatMessage(ChatMessage chatMessage) {
        return chatMessageDAO.createChatMessage(chatMessage);
    }

    @Override
    public Boolean updateChatMessage(ChatMessage chatMessage) {
        return chatMessageDAO.updateChatMessage(chatMessage);
    }

    @Override
    public Boolean deleteChatMessage(int messageID) {
        return chatMessageDAO.deleteChatMessage(messageID);
    }

    @Override
    public ChatMessage getChatMessageBySenderIDAndReceiverID(int senderID, int receiverID) {
        return chatMessageDAO.getChatMessageBySenderIDAndReceiverID(senderID,receiverID);
    }
}
